package com.djl.seckilldemo.utils;

import org.apache.commons.codec.digest.DigestUtils;

/**
 * @program: seckill-demo
 * @description: md5
 * @author: Mr.dai
 * @create: 2021-10-13 14:21
 **/

public class MD5Util {
    public static  String md5(String src){
        return DigestUtils.md5Hex(src);
    }

    public static  final  String SALT="1a2b3c4d";

    //第一次加密
    public static String inputPassToFormPass(String inputPass){
        //安全性，不将盐整体放进来
        String str=SALT.charAt(0)+SALT.charAt(2)+SALT.charAt(4)+inputPass+SALT.charAt(6)+SALT.charAt(1);
        return md5(str);
    }
    public static String formPassToDBPass(String formPass,String salt){
        String str=SALT.charAt(0)+SALT.charAt(2)+SALT.charAt(4)+formPass+SALT.charAt(6)+SALT.charAt(1);
        return md5(str);
    }
    public static String inputPassToDbpass(String inputPass,String salt){
        String formPass = inputPassToFormPass(inputPass);
        String dbPass= formPassToDBPass(formPass,salt);
        return dbPass;
    }

    public static void main(String[] args) {
        //f86f3a0cd62e7612bd75c0a738be3acd
        System.out.println(inputPassToFormPass("123456"));
        //ef994207b6d31ba07d59ac78676e3d04
        System.out.println(formPassToDBPass("f86f3a0cd62e7612bd75c0a738be3acd","1a2b3c4d"));
        System.out.println(inputPassToDbpass("123456","1a2b3c4d"));
    }
}
